package com.huoxingy.statics.services;

import com.huoxingy.statics.repo.MemberCountStaticsRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by hanxi on 2018/1/6.
 */
@Service
public class MemberCountStaticsServiceImpl implements MemberCountStaticsService {

    @Autowired
    private MemberCountStaticsRepo repo;

    @Override
    public List<Map<String, Object>> findOneByStoreIdAndBizDateAfter(String storeId) {
        OffsetDateTime d = OffsetDateTime.now(ZoneId.of("Asia/Shanghai"));
        String bizDate = d.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        OffsetDateTime c = d.plusDays(-7);
        String current = c.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        return repo.findByStoreIdAndBizDateBetweenOrderByBizDateAsc(storeId, current, bizDate);
    }


}
